<template>
  <j-modal
    :title="title"
    :width="1500"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="disableSubmit">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <j-vxe-table
              keep-source
              ref="table1"
              :loading="loading"
              :columns="columns"
              :dataSource="dataSource"
              :maxHeight="300"
              :disabled="disableSubmit"
              :rowNumber="true"
              :rowSelection="false"
              :toolbar="false"
            >
            </j-vxe-table>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>

import TicketCollectionManagementForm from './TicketCollectionManagementForm'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin'
import { getAction, postAction } from '@api/manage'
import { JVXETypes } from '@comp/jeecg/JVxeTable'

export default {
  name: 'SalesCollectionManagementAdjustmentModal',
  mixins: [JVxeTableModelMixin],
  components: {
    TicketCollectionManagementForm
  },
  data() {
    return {
      loading: false,
      dataSource: [],
      validatorRules:{},
      title:'费用调整',
      width:800,
      visible: false,
      disableSubmit: true,
      columns: [
        {
          title: '订单编号',
          key: 'schedulingNumber',
          align: 'center'
        },
        {
          title: '业务员',
          key: 'salesman_dictText',
          align: 'center'
        },
        {
          title:'客户名称',
          align:"center",
          key: 'customerName'
        },
        {
          title:'订单数量（吨）',
          align:"center",
          key: 'orderNum'
        },
        {
          title:'币种',
          align:"center",
          key: 'moneyUnit_dictText'
        },
        {
          title:'订单金额',
          align:"center",
          key: 'orderAmount'
        },
        {
          title:'发货金额',
          align:"center",
          key: 'shipmentAmount'
        },
        {
          title: '其他费用',
          align: "center",
          key: 'otherExpenses',
          type: JVXETypes.inputNumber,
        },
        {
          title: '费用备注',
          align:"center",
          key: 'expensesRemark',
          type: JVXETypes.input
        }
      ]
    }
  },
  methods:{
    adjustment(rows){
      this.visible=true
      this.disableSubmit=false
      this.dataSource=rows
      console.log("11111111111111111",this.dataSource)
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      this.submitForm();
    },
    submitForm(){
      if(this.dataSource[0].otherExpenses<=0){
        return this.$message.warning("其他费用不能小于等于零")
      }
      postAction('/procurement/salesCollectionManagement/adjust',this.dataSource[0]).then((res)=>{
        if(res.success){
          this.$message.success(res.message)
          this.visible=false
        }else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.confirmLoading = false
        this.dataSource=[]
        this.submitCallback()
      })
    },
    submitCallback(){
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style scoped>
</style>
